package com.ysd.lis.service.sta.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.dto.sta.StaDiagnosTempDto;
import com.ysd.lis.entity.sta.StaDiagnosTempDesc;
import com.ysd.lis.mapper.sta.StaDiagnosTempDescMapper;
import com.ysd.lis.service.sta.StaDiagnosTempDescService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 微生物-细菌报告-结果描述模板
 * </p>
 *
 * @author lm
 * @since 2024-12-06
 */
@Service
public class StaDiagnosTempDescServiceImpl extends ServiceImpl<StaDiagnosTempDescMapper, StaDiagnosTempDesc> implements StaDiagnosTempDescService {

    @Override
    public Result findDiagnosTempDescList(StaDiagnosTempDto param) {
        MPJLambdaWrapper<StaDiagnosTempDesc> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(StaDiagnosTempDesc.class);
        if (StringUtils.isNotBlank(param.getDiagnosType())) {
            queryWrapper.eq(StaDiagnosTempDesc::getDescType,param.getDiagnosType());
        }
        if (StringUtils.isNotBlank(param.getSearchValue())) {
            queryWrapper.like(StaDiagnosTempDesc::getDescType,param.getSearchValue());
        }

        queryWrapper.eq(StaDiagnosTempDesc::getDelFlag, 0)
                .orderByAsc(StaDiagnosTempDesc::getSeq);
        return Result.succ(1, "查询成功", this.baseMapper.selectList(queryWrapper));
    }

    @Override
    public Result batchDeleteDiagnosTempDesc(StaDiagnosTempDto dto) {
        List<StaDiagnosTempDesc> diagnosTempDescList = dto.getDiagnosTempDescList();
        List<String> ids = diagnosTempDescList.stream().map(StaDiagnosTempDesc::getId).collect(Collectors.toList());

        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }

    @Override
    public Result addDiagnosTempDesc(StaDiagnosTempDesc project) {
        int insert = this.baseMapper.insert(project);
        if(insert>0){
            return Result.succ(1, "添加成功", project);
        }else {
            return Result.succ(400, "添加失败", "");
        }
    }

    @Override
    public Result editDiagnosTempDesc(StaDiagnosTempDesc project) {
        int updateById = this.baseMapper.updateById(project);
        if(updateById>0){
            return Result.succ(1, "修改成功", project);
        }else {
            return Result.succ(400, "修改失败", "");
        }
    }

    @Override
    public Result batchUpdateDiagnosTempDesc(StaDiagnosTempDto dto) {
        List<StaDiagnosTempDesc> diagnosTempDescList = dto.getDiagnosTempDescList();

        boolean b = this.saveOrUpdateBatch(diagnosTempDescList);
        if(b){
            return Result.succ(1, "修改成功", null);
        }else {
            return Result.fail(400,"修改失败","");
        }
    }
}
